package team.common.utility;

import java.util.List;
import java.util.HashMap;
import java.util.Iterator;
import java.lang.String;

import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;


public class MakeXml 
{

	@SuppressWarnings("unchecked")
	public Document make(List list) throws Exception 
	{
		Element data = new Element("list");
		
		HashMap imgMap = new HashMap();
					
		if(list != null)
		{
			for(int i=0; i<list.size();i++)
			{    
				Element element = new Element("item");
				
				imgMap = (HashMap)list.get(i);
				Iterator iter = imgMap.keySet().iterator();
				
				while(iter.hasNext())
				{
					String name = (String)iter.next();
					Object value = (Object)imgMap.get(name);
					if (value == null) {
						addElement(element,name.toLowerCase(),"");
					} else {
						addElement(element,name.toLowerCase(),value.toString());
					}
				}
				data.addContent(element);
			}
		}
	
		Document document = new Document(data);
		return document;
	}
	
	public Element addElement(Element parent,String name, String value)
	{
		Element element = new Element(name);
		element.setText(value);
		parent.addContent(element);
		
		return parent;
	}
	
	public void addArrivute(Element element,String name,String value)
	{
		Attribute attribute = new Attribute(name,value);
		element.setAttribute(attribute);
	}
}

